<template>
<div class="icons">
 <swiper :options="swiperOption">
  <swiper-slide v-for="(page,index) of pages" :key="index" >
    <div class="icon" v-for="item of page" :key="item.id">
     <div class="icon-cont">
      <img class="icon-img" :src="item.imgUrl" />
     </div>
     <div class="icon-text">
       {{item.desc}}
     </div>
    </div>
  </swiper-slide>
 </swiper>
</div>
</template>

<script>
export default{
  props: ['iconList'],
  name: 'HomeIcons',
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~style/ellipsis.styl'
  .icons >>> .swiper-container
    width:100%
    height:0;
    padding-bottom:50%
    .icon
      height:0
      float:left
      width:25%
      padding-bottom:25%
      text-align:center
      .icon-text
        ellipsis()
      .icon-cont
        padding-top:0.3rem
        width:1.1rem
        height:1.1rem
        display:inline-block
        .icon-img
          width:100%
          height:100%
</style>
